// https://blog.csdn.net/weixin_47077674/article/details/120260433

import { InjectionKey } from "@vue/runtime-core"
import { createStore, Store, useStore as baseUseStore } from "vuex"
import createPersistedState from "vuex-persistedstate" //持久化
import { store as lang, LangState } from "./modules/lang"

//定义RootState接口，将所有模块类型放入
export interface RootState {
    lang: LangState
}
export const key: InjectionKey<Store<RootState>> = Symbol()

export const store: Store<RootState> = createStore({
    modules: { lang },
    plugins: [
        createPersistedState({
            paths: ["lang"],
        }),
    ],
})

export function useStore() {
    return baseUseStore(key)
}

